package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.vo.CustomerCardVO;
import com.example.mapper.CustomerCardMapper;
import com.example.service.CustomerCardService;
import com.example.utils.Result;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 客户银行卡视图服务实现类
 */
@Service
public class CustomerCardServiceImpl extends ServiceImpl<CustomerCardMapper, CustomerCardVO> implements CustomerCardService {

    /**
     * 根据客户ID查询银行卡信息
     */
    @Override
    public Result<List<CustomerCardVO>> getCardsByCustomerId(Integer customerId) {
        LambdaQueryWrapper<CustomerCardVO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CustomerCardVO::getCustomerId, customerId);
        
        List<CustomerCardVO> cards = list(queryWrapper);
        return Result.success(cards);
    }

    /**
     * 根据卡号查询银行卡信息
     */
    @Override
    public Result<CustomerCardVO> getCardInfo(String cardId) {
        // 使用自定义方法直接查询
        CustomerCardVO card = baseMapper.findByCardId(cardId);
        
        if (card != null) {
            return Result.success(card);
        } else {
            return Result.error("银行卡不存在");
        }
    }
} 